function [antseq, DRSSymInfo] = Function_Generate_DMRS_Seq(N_PRB, n_ID, NCS, Mode, Hopping)
	% Function_Generate_DMRS_Seq Method for creating the DMRS sequence
	 % Outputs: antseq      - Matrix of NTxAnts columns, each column contains stacked DMRS symbols corresponding to one subframe
	%          layerseq    - Matrix of NLayers columns, each column representing the two-slot DMRS signal for each layer
	%                        *before* precoding
    
    NLayers = 1;            % number of MIMO layers (1,2,3,or 4)
    PMI = 0;                % precoding matrix for MIMO transmissions
  	NTxAnts = 1;            % number of TX antennas (1,2, or 4)
	% --------------------------------------------------------------------------------------------------------
	% "Standard D2D": DMRS for all modes with two DMRS symbols per subframe:
	% --------------------------------------------------------------------------------------------------------
	
%     % by concatenation of collumns of the precoding matrices in 5.3.3.A2:
%  	W_NL1_NAnt2 = (1/sqrt(2)) * [1, 1, 1, 1, 1, 0; 1, -1, 1i, -1i, 0, 1];
% 	W_NL1_NAnt4 = (1/2) * [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 ;
%             1 1 1 1 1i 1i 1i 1i -1 -1 -1 -1 -1i -1i -1i -1i 0 0 0 0 1 1 1 1;
%             1 1i -1 -1i 1 1i -1 -1i 1 1i -1 -1i 1 1i -1 -1i 1 -1 1i -1i 0 0 0 0;
%             -1 1i 1 -1i 1i 1 -1i -1 1 -1i -1 1i -1i -1 1i 1 0 0 0 0 1 -1 1i -1i];
% 	W_NL2_NAnt4 = (1/2) * [1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0;
%             1 0 1 0 -1i 0 -1i 0 -1 0 -1 0 1i 0 1i 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1;
%             0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 -1 0 -1 0 0 1 0 -1 0 1 0 -1;
%             0 -1i 0 1i 0 1 0 -1 0 -1i 0 1i 0 1 0 -1 0 1 0 -1 0 1 0 -1 1 0 1 0 -1 0 -1 0];
% 	W_NL3_NAnt4 = (1/2) * [1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0;
%             1 0 0 -1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 1;
%             0 1 0 0 1 0 1 0 0 -1 0 0 0 0 1 0 0 1 1 0 0 -1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 ;
%             0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 -1 0 0 0 0 1 0 0 1 1 0 0 -1 0 0 1 0 0 -1 0 0];
    
    %%% Unknown Definitions    
    NCellID = 0;
    SeqGroup = 0;     
        
    switch Mode
        case 'psbch_V2X'
            layerseq = zeros(NLayers,(12 * N_PRB * 2 * 2)); % 12 [SCs/RB] * N_PRB [RBs] * 2 [slots/subframe] * 2 [DMRS/slot]
                
            for ii = [0, 1]    
                if N_PRB<6 && strcmp(Hopping,'Sequence')
                    warning('Sequence hopping method is not applied when number of RBs < 6');
                    Hopping = 'Off';
                end
                                    
                [u_s] = Function_DMRS_u_slots(Mode, Hopping, n_ID, NCellID, SeqGroup);
                [v_s] = Function_DMRS_v_slots(Hopping, n_ID, NCellID, SeqGroup);
                [a_s] = Function_DMRS_a_slots(Mode, n_ID, NCS, SeqGroup, NCellID, NLayers);
                [orth_code] = Function_DMRS_w_OOC(Mode, n_ID);
                
              	q_vec = [0, 0];
                for l = 0:NLayers-1
                	w_l = orth_code(1,l*2+1:l*2+2);
                    for slot = 0:1
                        [base_seq_slot, q_slot] =  Function_Base_Seq_Cyclic_Shift(N_PRB, u_s(slot+1), v_s(slot+1), a_s(l+1,slot+1));
                     	q_vec(slot+1) = q_slot;
                    	layerseq(l+1,12 * N_PRB * (2*ii+slot) +1 :12 * N_PRB * ((2*ii+slot)+1)) = ...
                            layerseq(l+1,12 * N_PRB * (2*ii+slot) +1 :12 * N_PRB * ((2*ii+slot)+1)) + ...
                            base_seq_slot * w_l(mod(slot,2)+1);
                    end
                end
            end
                
            %  update object info (with the parameters describing the
            %  DMRS sequences of the second slot
           	DRSSymInfo.Mode = Mode;
            DRSSymInfo.Alpha = a_s;
            DRSSymInfo.SeqGroup = u_s;
            DRSSymInfo.SeqIdx = v_s;
            DRSSymInfo.RootSeq = q_vec;
            DRSSymInfo.OrthoSeq = reshape(orth_code,NLayers,2);
                
            layerseq = layerseq(1:12 * N_PRB * 3); % discard the 4th DMRS symbol, as this mode only uses the first 3
            antseq = layerseq.';
            
        case 'pssch_V2X'
        %%%%% THIS IS NOT THE RIGHT VERSION! THIS IS "DUPLICATE PSSCH D2D"
            layerseq = zeros(NLayers,(12 * N_PRB * 2 * 2),1); % 12 [SCs/RB] * N_PRB [RBs] * 2 [slots/subframe] * 2 [DMRS/slot]
                
            for ii = [0, 1]
                if N_PRB<6 && strcmp(Hopping,'Sequence')
                 	warning('Sequence hopping method is not applied when number of RBs < 6');
                 	Hopping = 'Off';
            	end
                    
                [u_s] = Function_DMRS_u_slots(Mode, Hopping, n_ID, NCellID, SeqGroup);
                [v_s] = Function_DMRS_v_slots(Hopping, n_ID, NCellID, SeqGroup);
                [a_s] = Function_DMRS_a_slots(Mode, n_ID, NCS, SeqGroup, NCellID, NLayers);
                [orth_code] = Function_DMRS_w_OOC(Mode, n_ID);
                    
                q_vec = [0, 0];
            	for l = 0:NLayers-1
                	w_l = orth_code(1,l*2+1:l*2+2);
                	for slot = 0:1
                        [base_seq_slot, q_slot] =  Function_Base_Seq_Cyclic_Shift(N_PRB, u_s(slot+1), v_s(slot+1), a_s(l+1,slot+1));
                        q_vec(slot+1) = q_slot;
                        layerseq(l+1,12 * N_PRB * (2*ii+slot) +1 :12 * N_PRB * ((2*ii+slot)+1)) = ...
                            layerseq(l+1,12 * N_PRB * (2*ii+slot) +1 :12 * N_PRB * ((2*ii+slot)+1)) + ...
                        	base_seq_slot * w_l(mod(slot,2)+1);
                    end
                end
            end
                
            %  update object info (with the parameters describing the
            %  DMRS sequences of the second slot
           	DRSSymInfo.Mode = Mode;
            DRSSymInfo.Alpha = a_s;
            DRSSymInfo.SeqGroup = u_s;
            DRSSymInfo.SeqIdx = v_s;
            DRSSymInfo.RootSeq = q_vec;
            DRSSymInfo.OrthoSeq = reshape(orth_code,NLayers,2);
                
            antseq = layerseq.';
            
        case 'pscch_V2X'     
            layerseq = zeros(NLayers,(12 * N_PRB * 2 * 2)); % 12 [SCs/RB] * N_PRB [RBs] * 2 [slots/subframe] * 2 [DMRS/slot]
          	for ii = [0, 1]
                if N_PRB<6 && strcmp(Hopping,'Sequence')
                    warning('Sequence hopping method is not applied when number of RBs < 6');
                    Hopping = 'Off';
                end
                    
                [u_s] = Function_DMRS_u_slots(Mode, Hopping, n_ID, NCellID, SeqGroup);
                [v_s] = Function_DMRS_v_slots(Hopping, n_ID, NCellID, SeqGroup);
                [a_s] = Function_DMRS_a_slots(Mode, n_ID, NCS, SeqGroup, NCellID, NLayers);
                [orth_code] = Function_DMRS_w_OOC(Mode, n_ID);
                    
                q_vec = [0, 0];
             	for l = 0:NLayers-1
                	w_l = orth_code(1,l*2+1:l*2+2);
                	for slot = 0:1
                        [base_seq_slot, q_slot] =  Function_Base_Seq_Cyclic_Shift(N_PRB, u_s(slot+1), v_s(slot+1), a_s(l+1,slot+1));
                        q_vec(slot+1) = q_slot;
                        layerseq(l+1,12 * N_PRB * (2*ii+slot) +1 :12 * N_PRB * ((2*ii+slot)+1)) = ...
                         	layerseq(l+1,12 * N_PRB * (2*ii+slot) +1 :12 * N_PRB * ((2*ii+slot)+1)) + ...
                        	base_seq_slot * w_l(mod(slot,2)+1);
                    end
                end
        	end
                
            %  update object info (with the parameters describing the
            %  DMRS sequences of the second slot
           	DRSSymInfo.Mode = Mode;
            DRSSymInfo.Alpha = a_s;
            DRSSymInfo.SeqGroup = u_s;
            DRSSymInfo.SeqIdx = v_s;
            DRSSymInfo.RootSeq = q_vec;
            DRSSymInfo.OrthoSeq = reshape(orth_code,NLayers,2);
                
        	antseq = layerseq.';
            
        case 'pusch'
            
%         	if N_PRB<6 && strcmp(Hopping,'Sequence')
%                 warning('Sequence hopping method is not applied when number of RBs < 6');
%                 Hopping = 'Off';
%             end
%                 
%             [u_s] = Function_DMRS_u_slots(Mode, Hopping, n_ID, NCellID, SeqGroup);
%          	[v_s] = Function_DMRS_v_slots(Hopping, n_ID, NCellID, SeqGroup);
%           	[a_s] = Function_DMRS_a_slots(Mode, n_ID, NCS, SeqGroup, NCellID, NLayers);
%             [orth_code] = Function_DMRS_w_OOC(Mode, n_ID);
%                 
%             layerseq = zeros(NLayers,(12 * N_PRB * 2)); % 12 [SCs/RB] * N_PRB [RBs] * 2 [slots/subframe]
%             q_vec = [0, 0];
%             for l = 0:NLayers-1
%               	w_l = orth_code(1,l*2+1:l*2+2);
%                 for slot = 0:1
%                 	[base_seq_slot, q_slot] = Function_Base_Seq_Cyclic_Shift(N_PRB, u_s(slot+1), v_s(slot+1), a_s(l+1,slot+1));
%                     q_vec(slot+1) = q_slot;
%                  	layerseq(l+1,12 * N_PRB * slot +1 :12 * N_PRB * (slot+1)) = ...
%                     	layerseq(l+1,12 * N_PRB * slot +1 :12 * N_PRB * (slot+1)) + ...
%                       	base_seq_slot * w_l(mod(slot,2)+1);
%              	end
%             end
% 
%             %  update object info (with the parameters describing the
%             %  DMRS sequences of the second slot
%            	DRSSymInfo.Mode = Mode;
%             DRSSymInfo.Alpha = a_s;
%             DRSSymInfo.SeqGroup = u_s;
%             DRSSymInfo.SeqIdx = v_s;
%             DRSSymInfo.RootSeq = q_vec;
%             DRSSymInfo.OrthoSeq = reshape(orth_code,NLayers,2);
%                 
%             %MIMO precoding (return in column form)
%             if (NLayers==1) && (NTxAnts==1)
%                 antseq = layerseq.';
%         	elseif (NLayers==1) && (NTxAnts==2)
%              	W = W_NL1_NAnt2(:,PMI+1);
%               	antseq = (W * layerseq).';
%            	elseif (NLayers==1) && (NTxAnts==4)
%              	W = W_NL1_NAnt4(:,PMI+1);
%                 antseq = (W * layerseq).';
%             elseif (NLayers==2) && (NTxAnts==2)
%                 antseq = (1/sqrt(2)) * layerseq.';
%             elseif (NLayers==2) && (NTxAnts==4)
%                 W = W_NL2_NAnt4(:,PMI*2+1:PMI*2+2);
%                 antseq = (W * layerseq).';
%             elseif (NLayers==3) && (NTxAnts==4)
%                 W = W_NL3_NAnt4(:,PMI*3+1:PMI*3+3);
%                 antseq = (W * layerseq).';
%             elseif (NLayers==4) && (NTxAnts==4)
%                 antseq = (0.5 * layerseq).';
%             end
                
     	% --------------------------------------------------------------------------------------------------------
      	% "V2X":DMRS is essentially the concatenation of two (standard) D2D PUSCH DMRS
     	% --------------------------------------------------------------------------------------------------------
                
        case 'psdch'
           
        case 'psbch_D2D'
          
        case 'pssch_D2D'
              
        case 'pscch_D2D'
            
     end      

 
end % function